import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

// 引入国际化插件
import i18n from './language'

// 引入模拟数据
import '@/mock/attendances'

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
// 使用国际化插件，多种翻译
Vue.use(ElementUI, {
  i18n: (key) => i18n.t(key)
})

Vue.config.productionTip = false

import { imgerr } from '@/directives'
// 自定义指令处理图片错误
Vue.directive('imgerr', imgerr)

// 全局注册组件
// import PageTools from '@/components/PageTools'
// Vue.component('PageTools', PageTools)

// 使用Vue.use来注册
import myComponents from '@/components'
Vue.use(myComponents)

// 演示全局过滤
// Vue.filter('formatDate', val => val.slice(0, 7))

// 引入多过滤器
import * as filtersFn from '@/filters'
for (const key in filtersFn) {
  // 当前key都是函数名，可以通过filtersFn[key]得到函数
  Vue.filter(key, filtersFn[key])
}
// Object.keys(filtersFn).forEach(item => console.log(item))

// 混入注册
import mixinObj from '@/mixin'
Vue.mixin(mixinObj)

new Vue({
  el: '#app',
  router,
  store,
  // 挂载
  i18n,
  render: h => h(App)
})
